//
//  KTChoiceOneDeviceCell.m
//  RuiHeApp
//
//  Created by Jun on 2023/4/26.
//

#import "ChoiceOneDeviceCell.h"
#import "RHDeviceModel.h"

@interface ChoiceOneDeviceCell()
@property (nonatomic ,strong) QMUILabel *devNameLab;

@property (nonatomic ,strong) QMUILabel *devIdTitleLab;

@property (nonatomic ,strong) QMUILabel *devIdLab;

@property (nonatomic ,strong) QMUILabel *devStateLab;

@property (nonatomic ,strong) UIImageView *markView;

@end

@implementation ChoiceOneDeviceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}



- (void)setupUI{
    
    
    QMUILabel *devNameTitleLab = [[QMUILabel alloc] init];
    [devNameTitleLab setTextAlignment:NSTextAlignmentLeft];
    [devNameTitleLab setFont:kBOLDSYSTEMFONT(14)];
    [devNameTitleLab setTextColor:FontColor(@"#3F4443")];
    devNameTitleLab.text = [NSString stringWithFormat:@"%@:",@"设备名称".rh_localized];
    devNameTitleLab.numberOfLines = 2;
    devNameTitleLab.adjustsFontSizeToFitWidth = YES;
    devNameTitleLab.minimumScaleFactor = 0.8;
    [self.contentView addSubview:devNameTitleLab];

    
    _devNameLab = [[QMUILabel alloc] init];
    [_devNameLab setTextAlignment:NSTextAlignmentCenter];
    [_devNameLab setFont:kSYSTEMFONT(14)];
    [_devNameLab setTextColor:FontColor(@"#3F4443")];
    _devNameLab.adjustsFontSizeToFitWidth = YES;
    _devNameLab.minimumScaleFactor = 0.8;
    [self.contentView addSubview:_devNameLab];
    
    
    _devIdTitleLab = [[QMUILabel alloc] init];
    [_devIdTitleLab setTextAlignment:NSTextAlignmentLeft];
    [_devIdTitleLab setFont:kBOLDSYSTEMFONT(14)];
    [_devIdTitleLab setTextColor:FontColor(@"#3F4443")];
    _devIdTitleLab.text = [NSString stringWithFormat:@"%@:",@"设备ID".rh_localized];
    _devIdTitleLab.numberOfLines = 2;
    _devIdTitleLab.adjustsFontSizeToFitWidth = YES;
    _devIdTitleLab.minimumScaleFactor = 0.8;
    [self.contentView addSubview:_devIdTitleLab];

    
    _devIdLab = [[QMUILabel alloc] init];
    [_devIdLab setTextAlignment:NSTextAlignmentCenter];
    [_devIdLab setFont:kSYSTEMFONT(14)];
    [_devIdLab setTextColor:FontColor(@"#3F4443")];
    _devIdLab.adjustsFontSizeToFitWidth = YES;
    _devIdLab.minimumScaleFactor = 0.8;
    [self.contentView addSubview:_devIdLab];

    
    _markView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"agree"]];
    [_markView setBackgroundColor:UIColor.clearColor];
    [self.contentView addSubview:_markView];
    
    
    
    kWeakSelf;

    [_devNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_centerX).offset(-15);
        make.right.equalTo(weakSelf.markView.mas_left).offset(-5);
        make.centerY.equalTo(devNameTitleLab);
    }];
    
    [devNameTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(22);
        make.right.equalTo(weakSelf.devNameLab.mas_left).offset(-5);
        make.top.mas_offset(10);
       
    }];
    
    
    [_devIdLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.devNameLab);
        make.right.equalTo(weakSelf.markView.mas_left).offset(-5);
        make.centerY.equalTo(weakSelf.devIdTitleLab);
        make.bottom.mas_offset(-15);
    }];
    
    [_devIdTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(devNameTitleLab.mas_bottom).offset(5);
        make.left.mas_offset(22);
        make.right.equalTo(weakSelf.devIdLab.mas_left).offset(-5);
        make.bottom.mas_offset(-10);
    }];
    
    
    
    [_markView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.right.mas_offset(-22);
        make.centerY.mas_offset(0);
    }];
    
}

- (void)setDeviceModel:(RHDeviceModel *)deviceModel
{
    _deviceModel = deviceModel;
    _devNameLab.text = deviceModel.deviceName;
    _devIdLab.text   = deviceModel.deviceId;
    
}

- (void)setIsSelect:(BOOL)isSelect{
    _isSelect = isSelect;
    _markView.hidden = !isSelect;
}



@end
